package gui.scene;

import gui.EntityRenderer;

import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.util.HashMap;

import core.ViewableEntity;

/**
 * 
 * A layer which contains game entities.
 * 
 * Note: An entity layer does not have to necessarily contain ALL entities. For
 * example, if the game has ground units and air units, these units would be
 * stored in separate layers.
 * 
 * @author Jason
 * 
 */
public class EntityLayer implements Layer {

	protected final EntityRenderer eRenderer;

	protected final HashMap<Integer, ViewableEntity> entities = new HashMap<Integer, ViewableEntity>();

	public EntityLayer(EntityRenderer entityRenderer) {
		this.eRenderer = entityRenderer;
	}

	@Override
	public void render(Rectangle area, Graphics2D g) {
		for (Integer id : entities.keySet()) {
			ViewableEntity e = entities.get(id);
			if (area.contains(e.x, e.y, e.width, e.height)) {
				eRenderer.render(e, g);
			}
		}
	}

	public void addEntity(ViewableEntity e) {
		entities.put(e.id, e);
	}

}
